package com.foodapp.back.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.foodapp.back.common.Result;
import com.foodapp.back.dto.DishDTO;
import com.foodapp.back.service.DishService;
import com.foodapp.back.vo.DishVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 管理员菜品控制器
 */
@RestController
@RequestMapping("/admin/dish")
public class AdminDishController {

    @Resource
    private DishService dishService;

    /**
     * 分页查询菜品列表
     */
    @GetMapping("/list")
    public Result<Page<DishVO>> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) Long restaurantId,
            @RequestParam(required = false) String category,
            @RequestParam(required = false) String keyword) {
        
        Page<DishVO> result = dishService.pageList(page, size, restaurantId, category, keyword);
        return Result.success(result);
    }

    /**
     * 获取菜品详情
     */
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id) {
        DishVO dishVO = dishService.getDishById(id);
        return Result.success(dishVO);
    }

    /**
     * 新增菜品
     */
    @PostMapping
    public Result<Boolean> add(@RequestBody @Valid DishDTO dishDTO) {
        boolean result = dishService.addDish(dishDTO);
        return Result.success(result);
    }

    /**
     * 更新菜品
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody @Valid DishDTO dishDTO) {
        boolean result = dishService.updateDish(dishDTO);
        return Result.success(result);
    }

    /**
     * 删除菜品
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean result = dishService.deleteDish(id);
        return Result.success(result);
    }

    /**
     * 更新菜品状态
     */
    @PutMapping("/{id}/status")
    public Result<Boolean> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
        boolean result = dishService.updateStatus(id, status);
        return Result.success(result);
    }
}
